package bb.lanxing.net.okhttp;

import bb.lanxing.net.core.ApiClientConfig;
import java.io.IOException;
import okhttp3.Request;
import okhttp3.Response;
import rx.Observable;
import rx.functions.Func1;

public class RxJavaOkApiClient extends AbstractOkHttpApiClient<Observable<Response>> {
    public RxJavaOkApiClient(ApiClientConfig clientConfig) {
        super(clientConfig);
    }

    @Override
    public Observable<Response> execute(Request request) throws IOException {
        return Observable.just(request).flatMap(new Func1<Request, Observable<Response>>() {
            @Override
            public Observable<Response> call(Request request2) {
                try {
                    return Observable.just(RxJavaOkApiClient.this.doExecute(request2));
                } catch (IOException e) {
                    return Observable.error(e);
                }
            }
        });
    }
}
